﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

namespace DiskGarden
{
	public class Options
	{
		static protected string filename = "options.xml";
		static protected Options options;
		static public bool AllowHiddenFiles { get { return options.allowHiddenFiles; } set { options.allowHiddenFiles = value; } }
		static public bool AllowSystemFiles { get { return options.allowSystemFiles; } set { options.allowSystemFiles = value; } }
		static public string LanguageFile { get { return options.languageFile; } set { options.languageFile = value; } }


		public bool allowHiddenFiles = true;
		public bool allowSystemFiles = false;
		public string languageFile = "english.lng";

		static Options()
		{
			Load();
		}

		protected Options() { }

		static public void Load()
		{
			try
			{
				FileStream fsInput = new FileStream(filename, FileMode.Open);
				XmlSerializer xml = new XmlSerializer(typeof(Options));
				options = (Options)xml.Deserialize(fsInput);
				fsInput.Close();
			}
			catch (Exception)
			{
				if (options == null)
					options = new Options();
			}
		}

		static public void Save()
		{
			FileStream fsOutput = new FileStream(filename, FileMode.Create);
			XmlSerializer xml = new XmlSerializer(typeof(Options));
			xml.Serialize(fsOutput, options);
			fsOutput.Close();
		}
	}
}
